# -*- mode: python; -*-

#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#
import os

Import('CfgmEnv')
env = CfgmEnv.Clone()

setup_sources = [
    'setup.py',
    'requirements.txt',
    'run_tests.sh',
    'test-requirements.txt',
    '.testr.conf',
    '.coveragerc',
    'MANIFEST.in',
]

setup_sources_rules = []
for file in setup_sources:
    setup_sources_rules.append(
        env.Install(Dir('.'), "#controller/src/container/kube-cni/" + file))

local_sources = [
    'kube_cni/__init__.py',
    'kube_cni/kube_cni.py',
    'kube_cni/tests/__init__.py',
    'kube_cni/cni/__init__.py',
    'kube_cni/cni/cni.py',
    'kube_cni/common/__init__.py',
    'kube_cni/common/logger.py',
    'kube_cni/params/__init__.py',
    'kube_cni/params/params.py',
    'kube_cni/vrouter/__init__.py',
    'kube_cni/vrouter/vrouter.py',
]

local_sources_rules = []
for file in local_sources:
    target = "/".join(file.split('/')[:-1])
    local_sources_rules.append(
        env.Install(target, "#controller/src/container/kube-cni/" + file))

cd_cmd = 'cd ' + Dir('.').path + ' && '
sdist_depends = []
sdist_depends.extend(setup_sources_rules)
sdist_depends.extend(local_sources_rules)
sdist_gen = env.Command('dist/kube_cni-0.1dev.tar.gz', 'setup.py',
                        cd_cmd + 'python setup.py sdist')

env.Depends(sdist_gen, sdist_depends)
env.Default(sdist_gen)

if 'install' in BUILD_TARGETS:
    install_cmd = env.Command(None, 'setup.py',
                              cd_cmd + 'python setup.py install %s' %
                              env['PYTHON_INSTALL_OPT'])
    env.Depends(install_cmd, sdist_depends)
    env.Alias('install', install_cmd)

test_target = env.SetupPyTestSuite(sdist_gen)

# This add'l alias is to allow retry of UT in CI
env.Alias('controller/src/container/kube-cni/kube_cni:test', test_target)

# Local Variables:
# mode: python
# End:
